package cn.innosmart.aq.util;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by David on 2015/8/19.
 */
public class EditTextCheckUtil {
    /**
     * 验证邮箱
     *
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        boolean flag = false;
        try {
            String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }

    /**
     * 验证昵称
     *
     * @param nickName
     * @return
     */
    public static boolean checkNickName(String nickName) {
        return TextUtils.isEmpty(nickName);
    }

    /**
     * 检查昵称长度
     * @param nickName
     * @return
     */
    public static boolean checkNickNameLength(String nickName) {
        if (nickName.length() > 11) {
            return false;
        } else {
            return true;
        }
    }

    public static boolean checkPasswordEqual(String oldpassword, String newpassword) {
        return oldpassword.equals(newpassword);
    }

    public static boolean checkUsername(String username) {
        return TextUtils.isEmpty(username);
    }

    /**
     * 检查密码
     * @param oldpassword
     * @return
     */
    public static int checkPassword(String oldpassword) {
        if (TextUtils.isEmpty(oldpassword)) {
            return -11;
        }
        if (oldpassword.length() < 6) {
            return -12;
        }
        return 0;
    }

    /**
     * 检查是否是电话号码的正则判断
     *
     * @param tellNo
     * @return
     */
    public static boolean checkTelNo(String prefix, String tellNo) {
        if(prefix.equals("+086")) {
            if(tellNo.length() == 11 && tellNo.startsWith("1")) {
                return true;
            }
        } else if(prefix.equals("+886")) {
            if(tellNo.length() == 9 && tellNo.startsWith("9") ) {
                return true;
            }
        }

        return false;
    }
}
